package com.ve.everything;

import com.ve.everything.pojo.Responsejson;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.ResponseStatus;

@ControllerAdvice
public class MyExceptionHandler {
    private final static Logger logger = LoggerFactory.getLogger(MyExceptionHandler.class);

    @ResponseBody
    @ResponseStatus(HttpStatus.INTERNAL_SERVER_ERROR)
    @ExceptionHandler(value = Exception.class)
    public Responsejson javaExceptionHandler(Exception e){
        logger.error(e.getMessage(),e);
        Responsejson responsejson = new Responsejson();
        responsejson.setCode(2);
        responsejson.setMsg(e.getMessage());
        return responsejson;

    }
}
